package com.lanchetech.user.controller;

import com.lanchetech.bean.request.FreezeAmountReq;
import com.lanchetech.bean.request.WithdrawReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.response.WithdrawResp;
import com.lanchetech.bean.vo.CardFlowUsedSum;
import com.lanchetech.bean.vo.FreezeAmountVO;
import com.lanchetech.bean.vo.WithdrawVO;
import com.lanchetech.entity.AlipayAccount;
import com.lanchetech.entity.BankAccount;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.FundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(value = "用户资金接口", tags = "提现、佣金等")
@RequestMapping("/api/fund")
@RestController
public class FundController {

    @Autowired
    FundService fundService;

    @ApiOperation("获取提现记录分页")
    @PostMapping("/getWithdrawPage")
    public ResultData<BasePageResp<WithdrawResp>> getWithdrawPage(@AuthenticationPrincipal User user, @RequestBody WithdrawReq req) {
        return fundService.getWithdrawPage(user, req);
    }


    @ApiOperation("添加或编辑用户支付宝账号")
    @PostMapping("/editAlipayAccount")
    public BaseResp editAlipayAccount(@AuthenticationPrincipal User user, @RequestBody AlipayAccount alipayAccount) {
        return fundService.editAlipayAccount(user, alipayAccount);
    }

    @ApiOperation("获取用户支付宝账号")
    @GetMapping("/getAlipayAccount")
    public ResultData<AlipayAccount> getAlipayAccount(@AuthenticationPrincipal User user) {
        return fundService.getAlipayAccount(user);
    }

    @ApiOperation("添加或编辑银行卡账号")
    @PostMapping("/editBankAccount")
    public BaseResp editBankAccount(@AuthenticationPrincipal User user, @RequestBody BankAccount bankAccount) {
        return fundService.editBankAccount(user, bankAccount);
    }

    @ApiOperation("获取用户唯一的银行卡账号")
    @GetMapping("/getBankAccount")
    public ResultData<BankAccount> getBankAccount(@AuthenticationPrincipal User user) {
        return fundService.getBankAccount(user);
    }

    @ApiOperation("删除银行卡账号")
    @GetMapping("/deleteBankAccount")
    public BaseResp deleteBankAccount(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return fundService.deleteBankAccount(user, id);
    }

    @ApiOperation("获取银行卡列表")
    @PostMapping("/getBankAccountList")
    public ResultData<List<BankAccount>> getBankAccountList(@AuthenticationPrincipal User user) {
        return fundService.getBankAccountList(user);
    }

    @ApiOperation(value = "用户提现至自己的微信零钱（提现到微信零钱暂时未开通）")
    @PostMapping("/withdrawToAccount")
    public BaseResp withdrawToAccount(@AuthenticationPrincipal User user, @RequestBody WithdrawVO req, HttpServletRequest httpServletRequest) {
        return fundService.withdrawToAccount(user, req, httpServletRequest);
    }

    @ApiOperation(value = "用户嗨币已使用总和")
    @PostMapping("/getCardFlowUsedSum")
    public ResultData<CardFlowUsedSum> getCardFlowUsedSum(@AuthenticationPrincipal User user) {
        return fundService.getCardFlowUsedSum(user);
    }

    @ApiOperation("获取商家冻结金额分页")
    @PostMapping("/getFreezeAmountPage")
    public ResultData<BasePageResp<FreezeAmountVO>>  getFreezeAmountPage(@RequestBody FreezeAmountReq req) {
        return fundService.getFreezeAmountPage(req);
    }

}
